<?php
	$cs = Yii::app()->getClientScript();
	$jsMoment = 'moment.js';
	$jsDaterangepicker = 'daterangepicker.js';
	$cssFilename = 'daterangepicker-bs3.css';
	$cs->registerScriptFile(getAssetsUrl().'/'.$jsMoment, CClientScript::POS_HEAD);
	$cs->registerScriptFile(getAssetsUrl().'/'.$jsDaterangepicker, CClientScript::POS_HEAD);
	$cs->registerCssFile(getAssetsUrl().'/'.$cssFilename, '');
			
	function getAssetsUrl()
	{
		$assetsPath = Yii::getPathOfAlias('ext.daterangepicker');
		$assetsUrl = Yii::app()->assetManager->publish($assetsPath, false, -1);
		return $assetsUrl;
	}
	
	$set = Settings::model()->findByPk('1');
?>

<h1>Мониторинг редакторов</h1>

<?php 
	$pageSize=Yii::app()->user->getState('pageSize',Yii::app()->params['defaultPageSize']);

	$dialog = $this->widget('ext.ecolumns.EColumnsDialog', array(
	   'options'=>array(
			'title' => 'Настройки',
			'autoOpen' => false,
			'show' =>  'fade',
			'hide' =>  'fade',
		),
	   'htmlOptions' => array('style' => 'display: none'), //disable flush of dialog content
	   'ecolumns' => array(
			'gridId' => 'moneditors-grid', //id of related grid
			'storage' => 'session',  //where to store settings: 'db', 'session', 'cookie'
			'fixedLeft' => array('CCheckBoxColumn'), //fix checkbox to the left side 		
			'model' => $model->search(), //model is used to get attribute labels
			'columns' => array(
				array(
					'class'=>'bootstrap.widgets.TbButtonColumn',
					'template'=>'{delete}',
					'htmlOptions' => array('style'=>'width:50px'),
					'header'=>'',
				),				
				array
				(
					'class' => 'editable.EditableColumn',				
					'name'=>'date',
					'header'=>'Дата',					
					'value'=>'$data->date', 
					'filter'=>$this->widget('zii.widgets.jui.CJuiDatepicker', array(
							'model'=>$model,
							'attribute'=>'date', 
							'language' => 'ru',
							'htmlOptions' => array('id'=>'fdatepicker'),
							'options' => array('dateFormat'=>'yy-mm-dd')
						), true
					),
					'htmlOptions'=>array('style'=>'text-align: center'),
					'editable' => array(
						'type'       => 'date',
						'format'     => 'yyyy-mm-dd',
						'viewformat' => 'dd.mm.yyyy',				
						'url'        => $this->createUrl('moneditors/updatee'),
						'placement'  => 'right',
						'options' => array('datepicker' => array('language' => 'ru')),						
					),	
				),	
				array
				(
					'class' => 'editable.EditableColumn',				
					'name'=>'fio',
					'header'=>'Редактор',					
					'value'=>array($this, 'checkFio'),
					'filter' => array('' => 'Фильтр', 'voronina' => 'Воронина', 'zaslavsky' => 'Заславский', 'ejov' => 'Ежов', 'karabuto' => 'Карабуто', 'samkova' => 'Самкова', 'fomichev' => 'Фомичев', 'chanov' => 'Чанов'),
					'htmlOptions'=>array('style'=>'text-align: center'),
					'editable' => array(
						'type'     => 'select',
						'url'      => $this->createUrl('moneditors/updatee'),
						'placement'  => 'right',						
						'source'   => array('voronina' => 'Воронина', 'zaslavsky' => 'Заславский', 'ejov' => 'Ежов', 'karabuto' => 'Карабуто', 'samkova' => 'Самкова', 'fomichev' => 'Фомичев', 'chanov' => 'Чанов'),				
					),
				),		
				array
				(
					'class' => 'editable.EditableColumn',				
					'name'=>'journal',
					'header'=>'Издание',					
					'value'=>array($this, 'checkJournal'),
					'filter' => array('' => 'Фильтр', 'sst' => 'ССТ', 'ek' => 'ЭК', 'ekse' => 'ЭКСЭ', 've' => 'ВЭ', 'lm' => 'Лайтинг', 'elcom' => 'Элком'), 			
					'htmlOptions'=>array('style'=>'text-align: center'),
					'editable' => array(
						'type'     => 'select',
						'url'      => $this->createUrl('moneditors/updatee'),
						'placement'  => 'right',						
						'source'   => array('sst' => 'ССТ', 'ek' => 'ЭК', 'ekse' => 'ЭКСЭ', 've' => 'ВЭ', 'lm' => 'Лайтинг', 'elcom' => 'Элком'),				
					),
				),	
				array
				(
					'class' => 'editable.EditableColumn',				
					'name'=>'num',
					'header'=>'Номер',					
					'value'=>'$data->num',
					'filter' => array('' => 'Фильтр', '1' => '1','2' => '2','3' => '3','4' => '4','5' => '5','6' => '6','7' => '7','8' => '8','9' => '9','10' => '10','11' => '11','12' => '12'), 
					'htmlOptions'=>array('style'=>'text-align: center'),
					'editable' => array(
						'type'       => 'select',
						'url'        => $this->createUrl('moneditors/updatee'),
						'placement'  => 'right',
						'source'     => array('1' => '1','2' => '2','3' => '3','4' => '4','5' => '5','6' => '6','7' => '7','8' => '8','9' => '9','10' => '10','11' => '11','12' => '12'),
					),	
				),	
				array
				(
					'class' => 'editable.EditableColumn',				
					'name'=>'author',
					'header'=>'Автор',					
					'value'=>'$data->author',
					'htmlOptions'=>array('style'=>'text-align: center'),
					'editable' => array(
						'url'        => $this->createUrl('moneditors/updatee'),
						'placement'  => 'right',
						'inputclass' => 'span3',
					),
				),	
				array
				(
					'class' => 'editable.EditableColumn',				
					'name'=>'title',
					'header'=>'Название статьи',					
					'value'=>'$data->title',
					'htmlOptions'=>array('style'=>'text-align: center'),
					'editable' => array(
						'url'        => $this->createUrl('moneditors/updatee'),
						'placement'  => 'right',
						'inputclass' => 'span3',
					),
				),
				array
				(
					'class' => 'editable.EditableColumn',				
					'name'=>'dif',
					'header'=>'Коэффицент сложности',					
					'value'=>'$data->dif',
					'htmlOptions'=>array('style'=>'text-align: center'),
					'editable' => array(
						'url'        => $this->createUrl('moneditors/updatee'),
						'placement'  => 'right',
						'inputclass' => 'span3',
						'onSave' => 'js: function(e, params) { $.fn.yiiGridView.update("moneditors-grid"); }',
					),
				),	
				array
				(
					'class' => 'editable.EditableColumn',				
					'name'=>'count',
					'header'=>'Число знаков',					
					'value'=>'$data->count',
					'htmlOptions'=>array('style'=>'text-align: center'),
					'editable' => array(
						'url'        => $this->createUrl('moneditors/updatee'),
						'placement'  => 'right',
						'inputclass' => 'span3',
						//'onSave' => 'js: function(e, params) { $.fn.yiiGridView.update("moneditors-grid"); }',						
					),
				),	
				array
				(
					'class' => 'editable.EditableColumn',				
					'name'=>'type',
					'header'=>'Вид работы',					
					'value'=>array($this, 'checkType'),
					'filter' => array('' => 'Фильтр', 'auth' => 'Авторство', 'edit' => 'Редактирование', 'tran' => 'Перевод', 'read' => 'Вычитка'), 			
					'htmlOptions'=>array('style'=>'text-align: center'),
					'editable' => array(
						'type'       => 'select',
						'url'        => $this->createUrl('moneditors/updatee'),
						'placement'  => 'right',						
						'source'     => array('auth' => 'Авторство', 'edit' => 'Редактирование', 'tran' => 'Перевод', 'read' => 'Вычитка'), 
						//'onSave' => 'js: function(e, params) { $.fn.yiiGridView.update("moneditors-grid"); }',						
					),
				),
				array
				(
					'class' => 'editable.EditableColumn',				
					'name'=>'pay',
					'header'=>'Вознаграждение',					
					'value'=>'$data->pay',
					'htmlOptions'=>array('style'=>'text-align: center'),
					'editable' => array(
						'url'        => $this->createUrl('moneditors/updatee'),
						'placement'  => 'right',
						'inputclass' => 'span3',
						//'onSave' => 'js: function(e, params) { $.fn.yiiGridView.update("moneditors-grid"); }',
					),
				),
				/*array
				(
					'class' => 'editable.EditableColumn',				
					'name'=>'countdif',
					'header'=>'Число знаков с учетом коэффицента сложности',					
					'value'=>'$data->countdif',
					'htmlOptions'=>array('style'=>'text-align: center'),
					'editable' => array(
						'url'        => $this->createUrl('moneditors/updatee'),
						'placement'  => 'right',
						'inputclass' => 'span3',
					),
				),*/	
				array
				(	
					'name'=>'sum',
					'header'=>'Стоимость работы',		
					'value'=>'$data->sum',					
					'htmlOptions'=>array('style'=>'text-align: center'),
				),		
			),
		),
	));			

	$this->widget('bootstrap.widgets.TbButton', array('label'=>'Добавить запись','size'=>'normal','url'=>array('create')));
	echo "&nbsp;";
	$this->widget('bootstrap.widgets.TbButton', array('label'=>'Быстрое добавление','size'=>'normal','url'=>array('createquick')));	
	echo "&nbsp;".$dialog->link();
	echo "&nbsp;".CHtml::dropDownList('pageSize',$pageSize,array(10=>10,20=>20,50=>50,100=>100),array('onchange'=>"$.fn.updateGrid($(this).val())"))."";
	$this->widget('bootstrap.widgets.TbGridView', array(
		'id' => 'moneditors-grid',
		'itemsCssClass'=>'default',
		'type'=>'striped bordered condensed',
		'dataProvider'=>$model->search(),
		'columns' => $dialog->columns(),
		'template' => "{summary}\n{items}\n{pager}",	
		'filter'=>$model,
		'afterAjaxUpdate'=>"function(){
			jQuery.datepicker.setDefaults($.datepicker.regional['ru']);
			jQuery('#fdatepicker').datepicker({'dateFormat':'yy-mm-dd'})
		}",  
	));
?>		

<?php if (Yii::app()->user->name!='voronina' && Yii::app()->user->name!='ejov' && Yii::app()->user->name!='samkova' && Yii::app()->user->name!='fomichev'): ?>
<div style="background-color:#F5F5F5;padding:10px;">
	<div style="padding:10px;display:inline-table;">
		<div style="text-align:left;">
			<form class="form-horizontal">
			 <fieldset>
				 <div class="input-prepend">
				   <span class="add-on"><i class="glyphicon glyphicon-calendar icon-calendar"></i></span>
				   <input type="text" style="width: 160px" data-rel="" name="date-range" id="date-range" value="<?php echo date('Y/m/01').' - '.date('Y/m/d'); ?>" /> 
				 </div>		 
				<?php $listFio = array(
						'all' => 'Все',
						'voronina' => 'Воронина',
						'zaslavsky' => 'Заславский', 
						'ejov' => 'Ежов',
						'karabuto' => 'Карабуто',
						'samkova' => 'Самкова',
						'fomichev' => 'Фомичев',
						'chanov' => 'Чанов',					
					);
				?>		 
				<?php echo CHtml::dropDownList('fio',$select,$listFio); ?>
				<?php $this->widget('bootstrap.widgets.TbButton', array('label'=>'OK','size'=>'normal','htmlOptions'=>array('id'=>'send'))); ?>
			 </fieldset>
			</form>
			<div>Итого:&nbsp;<span id="result" style="color:red;"></span></div>
		</div>
	</div>		
	<div style="padding:10px;float:right;">
		<?php 
			echo "Статус месяца: ";
			echo CHtml::activeCheckBox($set,'close');
			$this->widget('ext.ibutton.IButton', array(
				'model'     => $set,
				'attribute' => 'close',
				'options' =>array(
					'labelOn'=>'Закрыт',
					'labelOff'=>'Открыт',
					'change'=>'js:function(){$.fn.setmonthstatus();}'
				)
			));
		?>
	</div>
	<div style="padding:10px;float:right;">
		<?php
			echo "Базовая ставка: ";
			$this->widget('editable.EditableField', array('type'=>'text','model'=>$set,'attribute'=>'base_payment','url'=>$this->createUrl('settings/updatee'),'placement'=>'right'));	
		?>
	</div>
</div>
<?php endif; ?>

<script type="text/javascript">
	$(function () {		
	
		$.ajax({        
			url: '<?php echo Yii::app()->createUrl('settings/checkmonth'); ?>',
			type: 'POST',				
			success: function (data) {
				console.log(data);
			},
			error: function(e) { console.log(e); },				
		});		
		
		$('#date-range').daterangepicker({
			format: 'YYYY/MM/DD',
			locale: {
				applyLabel: 'Ok',
				fromLabel: 'С',
				toLabel: 'По',
				daysOfWeek: ['Вс','Пн','Вт','Ср','Чт','Пт','Сб'],
				monthNames: ['Январь','Февраль','Март','Апрель','Май','Июнь','Июль','Август','Сентябрь','Октябрь','Ноябрь','Декабрь'],
				firstDay: 1
			}					
		});
		
		$("#send").click(function() {
			fio = $('#fio').val();
			range = $('#date-range').val();	
			$.fn.getpayment(fio, range);
		});	
	});
	
	$.fn.getpayment = function (fio, range) {
		$.ajax({        
			url: '<?php echo Yii::app()->createUrl('moneditors/ajaxgetpayment'); ?>',
			data: { fio: fio, range: range },
			type: 'POST',				
			success: function (data) {
				if (data) { 
					if (data.result.payment != 'false') { $('#result').text(data.result.payment); }
					else { $('#result').text("Нет данных за выбранный период"); }
				}
			},
			error: function(e) { console.log(e); },				
		});		
	}
	
	$.fn.setmonthstatus = function () {
		$.ajax({        
			url: '<?php echo Yii::app()->createUrl('settings/setstatus'); ?>',
			type: 'POST',				
			//success: function (data) { console.log(data);	},
			error: function(e) { console.log(e); },				
		});		
	}
</script>

<style>
	.ibutton-container {
		display: inline-block;
		vertical-align: middle;
	}
</style>